﻿$(function () {
    var $headerCheckBox = $("#ContentPlaceHolder1_gvApproveList_cboHeaderVoucher");
    var size = $(".cboItemVoucher").length;
    $headerCheckBox.click(function () {
        if ($headerCheckBox.prop("checked") === true) {
            for (var i = 0 ; i < size ; i++) {
                var $itemCheckBox = $("#ContentPlaceHolder1_gvApproveList_cboVoucher_" + i);
                $itemCheckBox.prop("checked", true);
            }
        }
        else {
            for (var i = 0 ; i < size ; i++) {
                var $itemCheckBox = $("#ContentPlaceHolder1_gvApproveList_cboVoucher_" + i);
                $itemCheckBox.prop("checked", false);
            }
        }
    });

    var $itemsCheckBox = $(".cboItemVoucher");
    $itemsCheckBox.click(function () {
        $headerCheckBox.prop("checked", true);
        for (var i = 0 ; i < size ; i++) {
            var $itemCheckBox = $("#ContentPlaceHolder1_gvApproveList_cboVoucher_" + i);
            if ($itemCheckBox.prop("checked") === false) {
                $headerCheckBox.prop("checked", false);
                break;
            }
        }        
    });
});